<?php 

namespace Home\Controller;
use Think\Controller;
/**
* 
*/
class LoginController extends Controller
{
	
	public function index(){
		layout(false);
		if (IS_POST) {
				
			$username = I('post.user_name');
			$sql = "SELECT * from `user` WHERE `username` = '$username'";
			$user = M('user');
			$query = $user -> query($sql);

			if(md5(I('post.password'))==$query[0]['password']){
					$_SESSION['id'] = $query[0]['id'];
					$_SESSION['username'] = $query[0]['username'];
					$_SESSION['face'] = $query[0]['head_img'];

						// array('username'=>,
						// 			'id'=>$query[0]['id'],     
						//       		'truename' => $query[0]['truename'],
						//         	'sex' =>  $query[0]['sex'],
						//        		'gid' =>  $query[0]['gid'],
						//        		'birthday' => $query[0]['birthday'],
						//        		'jobs' =>  $query[0]['jobs'],
	 				// 				'introduce' =>  $query[0]['introduce'],
						//      		'head_img' => $query[0]['head_img'],
						//         	'web' =>  $query[0]['web'],
						//         	'province' =>$query[0]['province'],
						//         	'city' =>  $query[0]['city'],
						//         	'qq' => $query[0]['qq'],
						//         	'phone' => $query[0]['phone'],
						//         	'email' =>  $query[0]['email'],
						//         	'site' => $query[0]['site'],
	 				// 				'score' => $query[0]['score'],
	 				// 			)
				
				if(I('post.net_auto_login')==1){

					cookie('username','$username',604800);//设置7天cookie
					cookie('password',I('post.password'),604800);

				}

				$this->success('登陆成功！',U('Home/setting/profile'));

			}

			

			
		}else{
			$this->display();
		}
		


	}

	public function check_ajax(){

		if (IS_POST) {
			
			$username = I('post.username');
			$user = M('user');
			$sql = "SELECT * FROM `user` WHERE `username` = '$username'";

			if(!$user->query($sql)){
				$data = 1;
				$this->ajaxReturn($data, 'json');
			}	
		}
		


	}

	public function loginout(){
		session_unset();
		session_destroy();
		$this->success('退出成功',U('Home/index/index'));
	}

}













 ?>